package com.koocloud.electroplatemanage.controller;

import com.koocloud.electroplatemanage.common.pojo.ResponseTemplate;
import com.koocloud.electroplatemanage.pojo.Quotation;
import com.koocloud.electroplatemanage.pojo.TypeWorkVo;
import com.koocloud.electroplatemanage.service.QuotationService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program:
 * @description:
 * @author: wjx
 * @create: 2020/11/13
 */
@RestController
@RequestMapping("/quotation")
public class QuotationController {
    static Logger log = Logger.getLogger("typework");
    @Autowired
    QuotationService quotationService;
    /**
     * @Description:通过pk查询工种表一条记录
     * @Param: [pk]
     * @return: com.koocloud.electroplatemanage.common.ResponseTemplate
     * @Author: wjx
     * @date: 2020/11/13
     */
    @RequestMapping(value = "/selectByPk", method = RequestMethod.POST, name = "主键查询")
    public ResponseTemplate selectByPk(@RequestParam(name="quotationCode") String pk) {
        //通过pk查询报价单表的一条记录
        return quotationService.selectByPk(Integer.valueOf(pk).intValue());
    }

    /**
     * @Description:通过名字查询最新的一个镀种报价的信息
     * @Param: [name]
     * @return: com.koocloud.electroplatemanage.common.ResponseTemplate
     * @Author: wjx
     * @date: 2020/11/13
     */
    @RequestMapping(value = "/selectByName",method = RequestMethod.POST,name = "名字查询")
   public ResponseTemplate selectByName(@RequestParam("quotationname") String name){
        //通过名字查询报价单的一条记录
        return quotationService.selectByName(name);
   }

    /**
     * @Description: 查询所有记录 分页 工种code/名称/线路
     * @Param: [page,limit  typeworkCode/name/line]
     * @return: com.koocloud.electroplatemanage.common.ResponseTemplate
     * @Author: wjx
     * @date: 2020/11/13
     */
    @RequestMapping(value = "/selectAllData", method = RequestMethod.POST, name = "全表查询")
   public ResponseTemplate selectAllData(String page, String limit, Quotation quotation){
       if (!StringUtils.isNotEmpty(page)) {
           page = "0";
       }
       if (!StringUtils.isNotEmpty(limit)) {
           limit = "0";
       }
       //查询所有记录 分页
       return quotationService.selectAllData(page,limit,quotation);
   }
    /**
     * @Description: 查询所有镀种记录 分页 镀种
     * @Param: [page,limit  name]
     * @return: com.koocloud.electroplatemanage.common.ResponseTemplate
     * @Author: wjx
     * @date: 2020/11/13
     */
    @RequestMapping(value = "/selectAllByName", method = RequestMethod.POST, name = "查询镀种所有记录")
    public ResponseTemplate selectAllByName(String page, String limit, String name){
        if (!StringUtils.isNotEmpty(page)) {
            page = "0";
        }
        if (!StringUtils.isNotEmpty(limit)) {
            limit = "0";
        }
        //查询所有记录 分页
        return quotationService.selectAllByName(page,limit,name);
    }

    /**
     *@Description:插入一条记录
     *@Param: [typeWorkVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/11/15
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST, name = "新增一条数据")
    public ResponseTemplate insert(@RequestBody Quotation quotation) {
        //插入一条记录
        return quotationService.insert(quotation);
    }

    /**
     *@Description:批量插入记录
     *@Param: [listQuotation]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: wjx
     *@date: 2020/11/16
     */
    @RequestMapping(value = "/batchInsert", method = RequestMethod.POST, name = "批量新增数据")
    public ResponseTemplate batchInsert(@RequestBody List<Quotation> listQuotation) {
        //批量插入记录
        return quotationService.batchInsert(listQuotation);
    }
    /**
     *@Description:逻辑删除一条记录
     *@Param: [pk]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST, name = "逻辑删除一条记录")
    public ResponseTemplate delete(@RequestParam(name="quotationId") String pk,@RequestParam(name="deleteFlag") String deleteFlag) {
        //逻辑删除一条记录
        return quotationService.delete(pk,deleteFlag);
    }
    /**
     *@Description:通过pks批量逻辑删除记录
     *@Param: [listPks]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: wjx
     *@date: 2020/11/16
     */
    @RequestMapping(value = "/batchDeleteByPks", method = RequestMethod.POST, name = "批量逻辑删除记录")
    public ResponseTemplate batchDeleteByPks(@RequestBody List<String> listPks) {
        //通过pks批量逻辑删除记录
        return quotationService.batchDeleteByPks(listPks);
    }
    /**
     *@Description:修改一条记录
     *@Param: [typeWorkVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST, name = "修改一条记录")
    public ResponseTemplate update(@RequestBody Quotation quotation) {
        //修改一条记录
        return quotationService.update(quotation);
    }
}
